/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.woundedwolf.android.tumbleweed.examples;

import android.graphics.Color;
import com.woundedwolf.android.tumbleweed.AbstractGame;
import com.woundedwolf.android.tumbleweed.Engine;
import com.woundedwolf.android.tumbleweed.Pixel;
import com.woundedwolf.android.tumbleweed.renderables.Pixels;
import com.woundedwolf.android.tumbleweed.elements.SimplexNoise;
import com.woundedwolf.android.tumbleweed.elements.Vector2D;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author FlameDuck
 */
public class Plasma extends AbstractGame
{
	private double height = 0;
	private Pixels pixels;

	public Plasma(Engine engine)
	{
		super(engine);
		pixels = new Pixels(16384);
		addRenderable(pixels);
		for (float y = 0; y < 128; y++)
			for (float x = 0; x < 128; x++)
			{
				Pixel pixel = getPixel(x, y);
				pixels.addPixel(pixel);
			}
	}

	@Override
	public void updateGame()
	{
		height += .02;

		for (Pixel pixel : pixels.getPixels())
		{
			double color = SimplexNoise.noise((-64+pixel.getPosition().getXpos())/64, (-64+pixel.getPosition().getYpos())/64, height);
			pixel.setColor(Color.HSVToColor(new float[] { 360.0f * (float) color, 1.0f, 1.0f }));
			pixels.updatePixel(pixel);
		}
	}

	private Pixel getPixel (float x , float y)
	{
		double color = SimplexNoise.noise((-64+x)/64, (-64+y)/64, height);
		Pixel pixel = new Pixel(new Vector2D(x,y), Color.HSVToColor(new float[] { 360.0f * (float) color, 1.0f, 1.0f }));
		return pixel;
	}
}
